package com.jprocms.module.cms.dal.dataobject.investigateitemoption;

import com.jpro.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jprocms.module.cms.dal.dataobject.investigateitem.InvestigateItemDO;
import lombok.*;

/**
 * 问卷调查条目选项 DO
 *
 * @author jprocms
 */
@TableName("cms_investigate_item_option")
@KeySequence("cms_investigate_item_option_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InvestigateItemOptionDO extends BaseDO {
    private static final long serialVersionUID = 1L;

    public double getPercent() {
        int total = getItem().getTotal();
        if (total > 0) {
            return (double) getOptionCount() * 100 / total;
        }
        return 0;
    }

    /**
     * ID
     */
    @TableId
    private Long id;
    /**
     * 站点ID
     */
    private Long siteId;
    /**
     * 问卷ID
     */
    private Long investigateId;
    /**
     * 选项ID
     */
    private Long investigateItemId;
    /**
     * 标题
     */
    private String title;
    /**
     * 得票数
     */
    private Integer optionCount;
    /**
     * 排序
     */
    private Integer optionSort;

    /**
     * 题目
     */
    @TableField(exist = false)
    private InvestigateItemDO item;

}
